//
//  AutographViewController.m
//  SelfDriving
//
//  Created by apple on 16/2/23.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "AutographViewController.h"

@interface AutographViewController ()<UITextViewDelegate>

@end

@implementation AutographViewController
{
    UITextView *feedback_Text;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;

    
    feedback_Text = [[UITextView alloc]initWithFrame:CGRectMake(8, 74, SCRE_WIDTH-16, 152)];
    feedback_Text.layer.borderWidth = 1;
    feedback_Text.text = @"最多输入300个字";
    feedback_Text.delegate = self;
    feedback_Text.layer.borderColor = UIColorFromRGB(0xafafaf).CGColor;
    [self.view addSubview:feedback_Text];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (IBAction)completeAction:(UIBarButtonItem *)sender {
    [self.delegate didSelectDates:[feedback_Text.text trim]];
    [self.navigationController popViewControllerAnimated:YES];

}
-(void)textViewDidBeginEditing:(UITextView *)textView{
    
    if ([textView.text isEqualToString:@"最多输入300个字"]) {
        
        textView.text = @"";
        textView.textColor = [UIColor blackColor];
    }
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    NSUInteger proposedNewLength = textView.text.length - range.length + text.length;
    if(text.length==0){
        return YES;
    }
    if (proposedNewLength > 300)
        return NO;//限制长度
    return YES;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
